/**
*┌──────────────────────────────────────────────────────────────┐
*│　@Author：liang.xie@micro-i.com.cn
*│　@Version：1.0.0
*│　@Date：2021-01-06
*|  @Brief: 量测项目的共享队列
*└──────────────────────────────────────────────────────────────┘
*/

#ifndef WORKPIECEBUFF_H
#define WORKPIECEBUFF_H

#include <condition_variable>
#include <string>
#include <vector>
#include <QMap>

class WorkpieceInfo;

class WorkpieceBuff
{
public:
    WorkpieceBuff();

    void SetData(const WorkpieceInfo &workpieceInfo);
    bool GetData(WorkpieceInfo &workpieceInfo);

    bool clear();
    WorkpieceBuff(const WorkpieceBuff& wpf) = delete;
    WorkpieceBuff& operator=(const WorkpieceBuff &wpf) = delete;
    void SetSize(std::size_t size);
    int Size();
    bool Empty();
    /***********************************************************************
     *  @function Exit
     *  @brief    唤醒条件变量并退出，防止两个条件变量一直等待
     *  @param
     *  @return
    ***********************************************************************/
    void Exit();

private:
    std::size_t                         begin_;
    std::size_t                         end_;
    std::size_t                         m_bufferedNum_;                // 已缓存数据的个数
    std::vector<WorkpieceInfo>          workpieceCircularBuffer_;
    std::condition_variable             m_notFullCv_;
    std::condition_variable             m_notEmptyCv_;
    std::mutex                          mutex_;
    bool                                m_exit_;
};

#endif // WORKPIECEBUFF_H
